Add __all__ in git.exc#1719
Merged
Byron merged 3 commits intogitpython-developers:mainfrom Oct 20, 2023
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1718
This adds
__all__ingit.exc, and adjusts__init__.pyimports.The
git.excmodule imports exceptions fromgitdb.excto republish them, as well as defining its own (also for use from outside). But because it did not define__all__, the intent for the exceptions it imported was unclear, since names that are introduced by imports and not present in__all__are not generally considered public, even when__all__is absent and a*import would reimport them.This rectifies that by adding
__all__and listing both imported and newly introduced exceptions explicitly in it. Although this strictly expands which names are public under typical conventions, it strictly contracts which names are imported by a*import, because the presence of__all__suppresses names not listed in it from being imported that way. However, because under typical conventions those other names are not considered public, and they were not even weakly documented as public, this should be okay.(Even though this is not a breaking change, in that code it would break would already technically be broken... if it turns out that it is common to wrongly rely on the availability of those names, then this may need to be revisited and slightly modified.)
This brings the readily identified public interface of
git.excin line with what is weakly implied (and intended) by its docstring.This also modifies
__init__.pyaccordingly: The top-level git module has for some time used a*import ongit.exc, causing the extra names originally meant as implementation details to be included. Because its own__all__was dynamically generated until c862845, #1659 also added 8edc53b to retain the formerly present names in__all__. So the change here imports those names from the modules that deliberately provide them, to preserve compatibility.